package com.example.task1.ui.user.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.User;
import com.example.task1.ui.BaseAdapter;
import com.example.task1.ui.user.activity.ChangePwdActivity;
import com.example.task1.ui.user.activity.FeedbackActivity;
import com.example.task1.ui.user.activity.OrderListActivity;
import com.example.task1.ui.user.activity.UserInfoActivity;

import java.util.List;

public class UserRvAdapter extends BaseAdapter<User> {

    private TextView title;
    private List<User> mData;
    private ImageView image;
    private Context context;

    public UserRvAdapter(Context context) {
        this.context = context;
    }

    public void setDate(List<User> data) {
        mData = data;
        notifyDataSetChanged();
    }

    @Override
    protected void setData(List<User> rows) {

    }

    @Override
    protected int getLayout() {
        return R.layout.user_text;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<User> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, User user) {
        title.setText(user.getTitle());
        image.setImageResource(user.getImage());
        holder.itemView.setOnClickListener(v -> {
            Intent intent;
            switch (user.getTitle()) {
                case "个人信息":
                    intent = new Intent(context, UserInfoActivity.class);
                    context.startActivity(intent);
                    break;
                case "订单列表":
                    intent = new Intent(context, OrderListActivity.class);
                    context.startActivity(intent);
                    break;
                case "修改密码":
                    intent = new Intent(context, ChangePwdActivity.class);
                    context.startActivity(intent);
                    break;
                case "意见反馈":
                    intent = new Intent(context, FeedbackActivity.class);
                    context.startActivity(intent);
                    break;
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        title = itemView.findViewById(R.id.title);
        image = itemView.findViewById(R.id.image);
    }
}
